﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

using DauGiaApp.Models;
namespace DauGiaApp.Models
{
    
    [MetadataType(typeof(DauGiaMetaData))]
    partial class DauGia
    {
        
        public DauGiaEntities data = new DauGiaEntities();
        public SanPham LaySanPham()
        {
            return data.SanPhams
                .Where(sp => sp.MaSanPham == this.MaSanPham)
                .Single();
        }

        public TaiKhoan LayTKDGCuoi()
        {
            DauGiaApp.Models.TaiKhoan tk = null;
            try
            {
                ChiTietDauGia ctdg = ChiTietDauGias.OrderByDescending(ct => ct.ThoiGianGiaoDich).ElementAt(0);
                if (ctdg == null)
                {
                    tk = new TaiKhoan();
                    tk.TenTaiKhoan = "Chưa có";
                }
                else
                {
                    tk = ctdg.TaiKhoan;
                }
            }
            catch (Exception ex)
            {
                tk = new TaiKhoan();
                tk.TenTaiKhoan = "Chưa có";
            }
            return tk;            
            
        }
    }
    public class DauGiaMetaData
    {
    }

}